package com.pospi.pospihold.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pospi.pospihold.R;
import com.pospi.pospihold.dto.CashierMsgDto;
import com.pospi.pospihold.ui.PrintSettingActivity;
import com.pospi.pospihold.util.PareseJson;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainLeftDrawerFragment extends Fragment {

    @Bind(R.id.store_name)
    TextView storeName;
    @Bind(R.id.cashier_name)
    TextView cashierName;
    //    @Bind(R.id.printer)
//    TextView printer;
    @Bind(R.id.ll_print)
    LinearLayout llPrint;

    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main_left_drawer, container, false);
        ButterKnife.bind(this, view);
        context = getActivity();

        String storename = context.getSharedPreferences("StoreMessage", Context.MODE_PRIVATE).getString("Name", "");
        String value = context.getSharedPreferences("Token", Context.MODE_PRIVATE).getString("value", "");
        String[] names = value.split("\\,");
        String deviceNo = names[2];//得到token的值
        int which = context.getSharedPreferences("islogin", Context.MODE_PRIVATE).getInt("which", 0);
        List<CashierMsgDto> cashierMsgDtos = new PareseJson().parese(context.getSharedPreferences("cashierMsgDtos", Context.MODE_PRIVATE).getString("cashierMsgDtos", ""));
        String name = cashierMsgDtos.get(which).getName();
        String id = cashierMsgDtos.get(which).getNumber();
        storeName.setText(storename + "-" + deviceNo);
        cashierName.setText(name + "-" + id);

//        byte status = PrnTest.prnStatus();
//        showStatus(status);
        return view;
    }

//

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick(R.id.ll_print)
    public void onClick() {
//        Intent intent = new Intent(getActivity(), PrintSettingActivity.class);
//        startActivity(intent);
    }
}
